package com.hot100.mid;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhengTao
 * @version 1.0
 * @description: 全排列
 * @date 2022/8/7 14:44
 */
public class Demo14 {
    public static void main(String[] args) {
        int[] num={0,1,2};
        List<List<Integer>> permute = permute(num);
        System.out.println(permute);

    }
    static List<List<Integer>> res=new ArrayList<>();
    static List<Integer>   tempRes=new ArrayList<>();
    public static List<List<Integer>> permute(int[] nums) {
         backTrack(nums,0);
         return res;
    }

    private static void backTrack(int[] nums, int i) {
        if(nums.length==i){
            res.add(new ArrayList<>(tempRes));
            return;
        }
        for (int j = 0; j <nums.length ; j++) {
            if(tempRes.contains(nums[j])){
                continue;
            }
            tempRes.add(nums[j]);
            backTrack(nums,i+1);
            tempRes.remove(tempRes.size()-1);
        }
    }
}
